#include "window.h"

void Window::generateWindow()
{
//    glwOrigin -> setCenter(center);
		xSlider = createSlider();
		ySlider = createSlider();
		zSlider = createSlider();

		if(glwInitial && glwUltimate && glwCurrent)
		{
			itrt = new QComboBox();
	    itrt -> setMaxVisibleItems(maxItemForItert);
			for(unsigned int i = 0; i < maxItemForItert; i++)
			{
				QString tmp;
				tmp.setNum(i);
				itrt -> addItem(tmp);
			}

			cluster = new QComboBox();
	    cluster -> setMaxVisibleItems(maxItemForCluster);
			for(unsigned int i = 0; i < maxItemForCluster; i++)
			{
				QString tmp;
				tmp.setNum(i);
				cluster -> addItem(tmp);
			}

      connect(xSlider, SIGNAL(valueChanged(int)), glwOrigin, SLOT(setXRotation(int)));
      connect(glwOrigin, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
      connect(ySlider, SIGNAL(valueChanged(int)), glwOrigin, SLOT(setYRotation(int)));
      connect(glwOrigin, SIGNAL(yRotationChanged(int)), ySlider, SLOT(setValue(int)));
      connect(zSlider, SIGNAL(valueChanged(int)), glwOrigin, SLOT(setZRotation(int)));
      connect(glwOrigin, SIGNAL(zRotationChanged(int)), zSlider, SLOT(setValue(int)));

			connect(xSlider, SIGNAL(valueChanged(int)), glwInitial, SLOT(setXRotation(int)));
      connect(glwInitial, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
      connect(ySlider, SIGNAL(valueChanged(int)), glwInitial, SLOT(setYRotation(int)));
      connect(glwInitial, SIGNAL(yRotationChanged(int)), ySlider, SLOT(setValue(int)));
      connect(zSlider, SIGNAL(valueChanged(int)), glwInitial, SLOT(setZRotation(int)));
      connect(glwInitial, SIGNAL(zRotationChanged(int)), zSlider, SLOT(setValue(int)));

			connect(xSlider, SIGNAL(valueChanged(int)), glwUltimate, SLOT(setXRotation(int)));
      connect(glwUltimate, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
      connect(ySlider, SIGNAL(valueChanged(int)), glwUltimate, SLOT(setYRotation(int)));
      connect(glwUltimate, SIGNAL(yRotationChanged(int)), ySlider, SLOT(setValue(int)));
      connect(zSlider, SIGNAL(valueChanged(int)), glwUltimate, SLOT(setZRotation(int)));
      connect(glwUltimate, SIGNAL(zRotationChanged(int)), zSlider, SLOT(setValue(int)));
			
			connect(xSlider, SIGNAL(valueChanged(int)), glwCurrent, SLOT(setXRotation(int)));
      connect(glwCurrent, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
      connect(ySlider, SIGNAL(valueChanged(int)), glwCurrent, SLOT(setYRotation(int)));
      connect(glwCurrent, SIGNAL(yRotationChanged(int)), ySlider, SLOT(setValue(int)));
      connect(zSlider, SIGNAL(valueChanged(int)), glwCurrent, SLOT(setZRotation(int)));
      connect(glwCurrent, SIGNAL(zRotationChanged(int)), zSlider, SLOT(setValue(int)));

	    connect(itrt, SIGNAL(activated(const QString&)), glwCurrent, SLOT(itrtSelected(const QString)));
	    connect(cluster, SIGNAL(activated(const QString&)), glwCurrent, SLOT(classSelected(const QString)));

      QHBoxLayout *mainLayout1 = new QHBoxLayout;
      QHBoxLayout *mainLayout2 = new QHBoxLayout;
      QVBoxLayout *secLayout = new QVBoxLayout;
      QHBoxLayout *thirdLayout = new QHBoxLayout;
      QVBoxLayout *ultimateLayout = new QVBoxLayout;

      mainLayout1->addWidget(glwOrigin);
      mainLayout1->addWidget(glwInitial);
      mainLayout2->addWidget(glwUltimate);
      mainLayout2->addWidget(glwCurrent);

	  	secLayout->addLayout(mainLayout1);
	  	secLayout->addLayout(mainLayout2);
			thirdLayout->addWidget(itrt);
			thirdLayout->addWidget(cluster);
	  	ultimateLayout->addLayout(secLayout);
	  	ultimateLayout->addLayout(thirdLayout);
      setLayout(ultimateLayout);
		}
		else
		{
			connect(xSlider, SIGNAL(valueChanged(int)), glwOrigin, SLOT(setXRotation(int)));
      connect(glwOrigin, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
      connect(ySlider, SIGNAL(valueChanged(int)), glwOrigin, SLOT(setYRotation(int)));
      connect(glwOrigin, SIGNAL(yRotationChanged(int)), ySlider, SLOT(setValue(int)));
      connect(zSlider, SIGNAL(valueChanged(int)), glwOrigin, SLOT(setZRotation(int)));
      connect(glwOrigin, SIGNAL(zRotationChanged(int)), zSlider, SLOT(setValue(int)));

      QHBoxLayout *mainLayout = new QHBoxLayout;
      mainLayout->addWidget(glwOrigin);
      mainLayout->addWidget(xSlider);
      mainLayout->addWidget(ySlider);
      mainLayout->addWidget(zSlider);
      setLayout(mainLayout);
		}
}

QSlider *Window::createSlider()
{
    QSlider *slider = new QSlider(Qt::Vertical);
    slider->setRange(0, 360 * 16);
    slider->setSingleStep(16);
    slider->setPageStep(15 * 16);
    slider->setTickInterval(15 * 16);
    slider->setTickPosition(QSlider::TicksRight);
    return slider;
}

